var selectSort = function (arr) {
    let len = arr.length
    for (let i = 0; i < len ; i++) {
        let min = arr[i]
        let minIndex = i
        for (let j = i; j < len; j++) {
            if (arr[j] < min) {
                min = arr[j]
                minIndex = j
            }
        }
        arr[minIndex] = arr[i]
        arr[i] = min
    }
    return arr
}


let arr = [5,4,6,3,7,2,1]
console.log(selectSort(arr))